<?php
/**
 * Created by PhpStorm.
 * User: 17208
 * Date: 2020/9/29
 * Time: 14:21
 */
namespace extend;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

class Log
{
    private static $instance = [];
    private static $path = 'data/logs/';
    /**
     * @param $name string
     * @param $file string
     * @return Logger
     */
    public static function getInstance($name,$file=null)
    {
        $key = md5(json_encode(['name'=>$name,'file'=>$file]));

        if(!isset(self::$instance[$key])){
            $log = new Logger($name);
            !$file && $file = date('Ymd');
            $stream = self::$path.$file.'.log';
            $log->pushHandler(new StreamHandler($stream, Logger::INFO));
            self::$instance[$key] = $log;
        }

        return self::$instance[$key];
    }
}